package com.usbserial.core;

import android.hardware.usb.UsbDevice;

import com.usbserial.driver.DriverType;

/**
 * Value object describing a detected USB serial capable device.
 */
public class UsbSerialDeviceInfo {

    private final UsbDevice usbDevice;
    private final DriverType driverType;

    public UsbSerialDeviceInfo(UsbDevice usbDevice, DriverType driverType) {
        this.usbDevice = usbDevice;
        this.driverType = driverType;
    }

    public UsbDevice getUsbDevice() {
        return usbDevice;
    }

    public int getVendorId() {
        return usbDevice.getVendorId();
    }

    public int getProductId() {
        return usbDevice.getProductId();
    }

    public String getDeviceName() {
        return usbDevice.getDeviceName();
    }

    public String getManufacturerName() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            return usbDevice.getManufacturerName();
        }
        return null;
    }

    public String getProductName() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            return usbDevice.getProductName();
        }
        return null;
    }

    public String getSerialNumber() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            try {
                return usbDevice.getSerialNumber();
            } catch (SecurityException ignored) {
                return null;
            }
        }
        return null;
    }

    public int getInterfaceCount() {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            return usbDevice.getInterfaceCount();
        }
        return 0;
    }

    public DriverType getDriverType() {
        return driverType;
    }
}
